var t = require("../../../@babel/runtime/helpers/interopRequireDefault")(require("../../../dist/dialog/dialog")), o = getApp(), a = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ a ],
    data: {
        orderShow: !1,
        imageRight: !0,
        orderId: null,
        goodsId: null,
        refundId: null,
        addressDetail: "",
        storeName: "",
        couponStore: {},
        couponList: [],
        usableCoupon: [],
        couponCode: "",
        latitude: "",
        longitude: "",
        details: {},
        storeListByGoods: [],
        orderType: "shop",
        evaluateType: 0,
        succees: 0,
        showService: !1,
        customerOpen: !1,
        cservice: "",
        serviceQRcode: "",
        serviceMobile: ""
    },
    onLoad: function(t) {
        var o, e = this;
        "" !== (null !== (o = t.orderId) && void 0 !== o ? o : "") && this.setData({
            orderId: Number(t.orderId)
        });
        try {
            wx.removeStorageSync("applyaddresspoint");
        } catch (t) {}
        this._getLocation(function(t, o) {
            e.setData({
                longitude: o.lng,
                latitude: o.lat
            }), e.storeorderDetails();
        }), this.orderCoupon();
    },
    onShow: function() {
        try {
            var t = wx.getStorageSync("applyaddresspoint");
            console.log(t), t && (console.log(t), this.setData({
                longitude: e.lng,
                latitude: e.lat
            }), console.log(this.data.longitude));
        } catch (t) {
            console.log(t);
        }
    },
    service: function() {
        var t = this, e = o.getNetAddresss("goods.customer-service.index");
        o._postNetWork({
            url: e,
            data: {
                goods_id: this.data.goodsId
            },
            success: function(o) {
                var e = o.data;
                1 == e.result && t.setData({
                    customerOpen: e.data.customer_open,
                    cservice: e.data.cservice,
                    serviceQRcode: e.data.service_QRcode,
                    serviceMobile: e.data.service_mobile
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    orderCoupon: function() {
        var t = this;
        wx.showLoading({
            title: "加载中"
        });
        var e = o.getNetAddresss("plugin.coupon-store.frontend.order.orderCoupon"), a = {
            order_id: this.data.orderId
        };
        o._postNetWork({
            url: e,
            data: a,
            success: function(o) {
                var e, a, s = o.data, n = s.data;
                e = n.find(function(t) {
                    return 0 === t.status;
                }), a = n.filter(function(t) {
                    return 0 === t.status;
                }), 1 == s.result ? (wx.hideLoading(), t.setData({
                    couponList: s.data,
                    couponCode: e,
                    usableCoupon: a
                })) : wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    copyCode: function(t) {
        var o = t.currentTarget.dataset.text;
        wx.setClipboardData({
            data: o,
            success: function(t) {
                wx.getClipboardData({
                    success: function(t) {
                        wx.showToast({
                            title: "复制成功"
                        });
                    }
                });
            }
        });
    },
    getStoreListByGoods: function() {
        var t = this, e = o.getNetAddresss("plugin.coupon-store.frontend.store.getStoreListByGoods"), a = {
            goods_id: this.data.goodsId,
            longitude: this.data.longitude,
            latitude: this.data.latitude
        };
        o._postNetWork({
            url: e,
            data: a,
            success: function(o) {
                var e, a = o.data, s = null === (e = o.data.data) || void 0 === e ? void 0 : e.data, n = "".concat(s[0].city).concat(s[0].district).concat(s[0].street).concat(s[0].address);
                1 == a.result ? t.setData({
                    addressDetail: n,
                    storeListByGoods: a.data.data
                }) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    orderstateOn: function(o) {
        var e = this, a = o.currentTarget.dataset, s = a.id, n = a.value, i = a.api;
        9 === n && t.default.confirm({
            title: "提示",
            message: "确定取消该订单?"
        }).then(function() {
            e.cancelPay(s, i);
        }).catch(function() {}), 1 === n && wx.navigateTo({
            url: "/packageD/buy/orderPay/orderPay?order_id=" + s + "&status=2"
        });
    },
    cancelPay: function(t, e) {
        var a = this, s = o.getNetAddresss(e), n = {
            order_id: t
        };
        o._postNetWork({
            url: s,
            data: n,
            success: function(t) {
                var o = t.data;
                1 == o.result ? (wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                }), a.storeorderDetails()) : wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    refreshCode: function() {
        this.orderCoupon();
    },
    navigationLocation: function() {
        wx.navigateTo({
            url: "/packageC/o2o/o2oLocation_loc/o2oLocation_loc?tag=storeApply"
        });
    },
    shopNavTo: function() {
        wx.navigateTo({
            url: "/packageF/consumption/shopList/shopList?goodsId=".concat(this.data.goodsId, "&longitude=").concat(this.data.longitude, "&latitude=").concat(this.data.latitude)
        });
    },
    onClose: function() {
        this.setData({
            orderShow: !this.data.orderShow
        });
    },
    onQrcode: function() {
        this.setData({
            orderShow: !0
        });
    },
    storeorderDetails: function() {
        var t = this, e = o.getNetAddresss("order.detail"), a = {
            order_id: this.data.orderId,
            basic_info: 1
        };
        o._getNetWork({
            url: e,
            data: a,
            success: function(o) {
                var e, a, s, n, i, r, d = o.data;
                1 == d.result ? (console.log(null === (e = d.data.has_many_order_goods[0]) || void 0 === e ? void 0 : e.goods_id), 
                t.setData({
                    couponStore: d.data.coupon_store,
                    details: d.data,
                    goodsId: null === (a = d.data.has_many_order_goods[0]) || void 0 === a ? void 0 : a.goods_id,
                    refundId: d.data.refund_id,
                    storeName: null === (s = d.data.coupon_store.coupon_list[0]) || void 0 === s || null === (n = s.has_one_store) || void 0 === n ? void 0 : n.store_name,
                    pluginSetting: null === (i = d.basic_info) || void 0 === i || null === (r = i.plugin_setting) || void 0 === r ? void 0 : r.coupon_store
                }), t.getStoreListByGoods(), t.service()) : wx.showToast({
                    icon: "none",
                    title: d.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    evaluateBtn: function(t) {
        var o = t.currentTarget.dataset.sotrename;
        wx.navigateTo({
            url: "/packageF/consumption/evaluate/evaluate?orderId=".concat(this.data.orderId, "&type=1&storeName=").concat(o)
        });
    },
    refundBtn: function() {
        wx.navigateTo({
            url: "/packageF/consumption/refundOrder/refundOrder?orderId=".concat(this.data.orderId, "&type=2&orderType=1")
        });
    },
    afterSaleBtn: function() {
        wx.navigateTo({
            url: "/packageF/consumption/refundProcess/refundProcess?refundId=".concat(this.data.refundId)
        });
    },
    showPop: function() {
        console.log("12342");
        var t = o._isTextEmpty(this.data.serviceQRcode) && o._isTextEmpty(this.data.serviceMobile);
        if (o._isTextEmpty(this.data.cservice) && t) return o.tips("抱歉，暂未设置客服信息");
        o._isTextEmpty(this.data.cservice) || !t ? this.setData({
            serviceShow: !0
        }) : this.gotoChat({
            currentTarget: {
                dataset: {
                    cservice: this.data.cservice
                }
            }
        });
    },
    closePop: function() {
        this.setData({
            serviceShow: !1
        });
    },
    gotoChat: function(t) {
        console.log(t);
        var e = t.currentTarget.dataset.cservice + "&goods_id=" + this.data.goodsId;
        wx.navigateTo({
            url: e,
            fail: function(t) {
                o.tips("客服路由出错");
            }
        });
    },
    onReady: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {}
});